package org.sky.platform.service;

import java.util.List;

import org.sky.platform.client.UserMapper;
import org.sky.platform.model.UserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

@Service
public class UserService {
	//定义一个全局的记录器，通过LoggerFactory获取
    private final static Logger logger = LoggerFactory.getLogger(UserService.class);
    @Autowired
    private UserMapper userMapper;

    /**
     * 单个查询测试
     *
     * @return
     */
    public UserModel testDBSelectOne() {
        return userMapper.selectOne();
    }

    /**
     * 使用分页插件pageHelper
     *
     * @return
     */
    public PageInfo<UserModel> testDBSelectAll() {
        PageHelper.startPage(3, 10);
        List<UserModel> userModels = userMapper.selectAll();
        PageInfo<UserModel> userModelPageInfo = new PageInfo<>(userModels);
        logger.info(">>>>>userModels:" + JSON.toJSONString(userModels));
        logger.info(">>>>>userModelInfo:" + JSON.toJSONString(userModelPageInfo));
        return userModelPageInfo;
    }
}